//
//  stats.hpp   --- Handles statistical functions
//
#include "object.hpp"
#include "bb.hpp"
#include "bag.hpp"
#include "strng.hpp"

#define ACCUM_COUNT 10                  // number of dwgs to accumulate avg

#define MAX_GAPS    HIGHEST_NUMBER + 1
#define ALL_DRAWINGS 32767
#define MAX_MOST_DRAW  6
#define MAX_LEAST_DRAW  6

#define LINES_PER_PAGE  18

//
//  Lotto Machine (handles random number generation / selection
//
enum    LMState    { LM_INIT, LM_RUNNING, LM_SELECT };

class LottoMachine : public Object
{
private:
    LNUM    ballList1[HIGHEST_NUMBER];          // shuffle lists
    LNUM    ballList2[HIGHEST_NUMBER];          // shuffle lists
    int     fillList;                           // index of list to fill
    int     destIndex;                          // dest. index for fill
    LMState machineState;
public:
    LottoMachine() {  }
    reset();                                    // reset lotto machine
    void    step();                             // step lotto machine
    LNUM    getBall( BOOL takeOut = TRUE);      // get a ball out of lotto
};

//
//  Each lottery drawing is tracked using the following object
//
class LottoDrawing : public Object
{
public:
//  Base data from lotto history file
    int     drawingNo;                  // which drawing in sequence
    int     month, day, year;           // date of drawing
    LNUM    lottoNumbers[ MAX_NUMBERS ]; // numbers drawn

// Calculated Information
    LNUM    spread;                     // range of values
    long    sum;
    float   average;
    float   stdDeviation;
    float   variance;
    LNUM    nbrOdds, nbrEvens;
    LNUM    gaps[ MAX_GAPS ];
    float   gapAverage;
    int     cumAverage;                 // cumulative average (10 dwgs.)
    int     runTotal;                   // cum. total - 1 dwg (prev 9 dwgs.)


//  Methods of manipulating lottery stats object
    LottoDrawing();
    isA()       { return OBJTYPE_APP; }

    BOOL    loadDrawing( int dwgNo, int mon, int dy, int yr,
			 int n1, int n2, int n3, int n4, int n5, int n6 );
    void    sort();
    void    recalcStats();
    void    showStats( BOOL bShowHeading );    
};

class LottoList : public Object
{
public:
    Bag     drawingList;

    int     numDrawings;                // number of drawings for stats
    LNUM    hitList[ HIGHEST_NUMBER ];        // total hits for each number
    LNUM    dwgsSinceHit[ HIGHEST_NUMBER ];   // # drawings since last hit
    LNUM    mostDrawn[ MAX_MOST_DRAW ]; // most drawn numbers
    LNUM    leastDrawn[ MAX_LEAST_DRAW ]; // least drawn numbers
    long    sumTotal;                   // total of "sum" of each dwg
    float   avgTotal;                   // average of total
    float   avgSpread;                  // average spread of total
    int     totalOdd, totalEven;        // total odd/even
    float   avgOdd;                     // average number of odd #
    float   avgEven;                    // average number of eve #
    float   pctOdd, pctEven;            // percent Odds / Evens
    LNUM    avgGap[ MAX_GAPS ];         // average each gap
    float   avgAllGaps;                 // average of all gaps

    LottoList() { }
    ~LottoList();
    isA()       { return OBJTYPE_APP; }

    BOOL    loadFromFile( char *pFileName );
    BOOL    saveToFile( char *pFileName );
    void    killList(void);
    BOOL    addToList(LottoDrawing& aDrawing);
    BOOL    recalcStats( int howMany=32767 );
    void    showStats( int nDrawings );
    void    showMostHits();
    void    showHits();
    void    showSinceHits();
    void    showOverdues( int pageMax=LINES_PER_PAGE );
    void    showTotals( BOOL bShowHeading );
    BOOL    enoughDrawings();
};

